/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller.actions;

import controler.formbeans.NewsBean;
import java.util.Vector;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.logic.db.CommonWSFunctionality;
import model.pojo.News;
import model.pojo.NewsCategories;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author Maha
 */
public class CategoryAction extends org.apache.struts.action.Action {

    /* forward name="success" path="" */
    /**
     * This is the action called from the Struts framework.
     *
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        CommonWSFunctionality ws = new CommonWSFunctionality();
        int id = Integer.parseInt(request.getParameter("id"));
        Vector<News> ne = ws.getNewsOREvent(id);
        String val = "";
        for (News news : ne) {
            val = news.getNewsCategories().getNewsCategoryTitle();
            break;
        }
        ((NewsBean) form).setEvents(ne);
        NewsCategories n = new NewsCategories(val);
        ((NewsBean) form).setNewsCategories(n);
        ((NewsBean) form).setNewsDescription("");
        ((NewsBean) form).setNewsImage("");
        ((NewsBean) form).setNewsTitle("");


        Vector<NewsCategories> cat = ws.getCat();
        ((NewsBean) form).setNewsCat(cat);

        return mapping.findForward("news");
    }
}
